Workflow Transition Task

Set of Transition Tasks

Depending on what you need or what you want to automate, each Workflow Transition Task can have tasks of the following types:

• App-Defined Actions: These are actions that developers write in code and define in the Frappe app using hooks.py. These actions can automatically make records, check conditions, or do backend tasks.

• Server Scripts: These are scripts that can be changed in ERPNext's scripting interface. They let administrators set up dynamic behaviours without having to change the backend code. Great for people who know how to script but aren't developers.

• Webhooks: These are used to send data to outside systems or services when the transition happens. Good for things like sending alerts to Slack, updating external CRMs, and more.

A Task for Transitioning a Server Script

You can connect a transition to a Server Script. This is helpful if you want the system to run custom logic without changing the app's backend code. These scripts use the same document as a context, which is the document that is changing.

Different kinds of tasks for moving from one workflow to another

You can set up each Transition Task to run in one of two ways:

Tasks that happen at the same time:

• This is how it works by default.

• Tasks are done one at a time, in order.

• The whole transition is rolled back if even one task fails.

• Helpful when the outcome of one task depends on another or when you want to be in charge of and trust the outcome completely.

Tasks that happen at different times:

• These tasks are done after the state change is completely finished.

• They don't have any effect on whether the transition works or not.

• Run in a separate background job so they don't stop the user.

• Great for sending emails, keeping logs up to date, or letting other systems know.

When you set up the task, you can turn on this mode by checking the "Asynchronous" box.

Actions Defined by Apps

Using the workflow_methods hook in hooks.py, developers write the code for these actions in the app's codebase. These actions are usually backend logic that needs to run automatically when things change.

• The parameter doc: Document must be accepted by these methods.

• The doc points to the instance of the document that is going through the state change.

For example:

python

Copy Edit

hooks.py

workflow_methods = [{

"Name": "Make a customer,"

"method": "myapp.shop.doctype.kirana.create_customer" ]

myapp/shop/doctype/kirana.py

def make_customer(doc):

customer = frappe.new_doc("Customer")

customer.customer_name = "Customer " + doc.name;

customer.customer_type = "Individual"

save customer()

This means that when the workflow changes, the system will automatically make a new Customer document using the information from the old one.

When you set up a Workflow Transition Task, any app that has defined these kinds of methods will show up in the "Tasks" dropdown.

⚠️ Important Note for Users:

You can't make App-Defined Actions yourself if you aren't a developer or don't have access to the app's backend code. You should use Server Scripts instead (see next section).

Scripts for Servers

Users can write and manage Server Scripts from within the ERPNext interface. You can set up workflow actions without changing the backend code with them.

• These scripts also take the doc: Document as input, just like app-defined methods do.

• When you make the script, you need to choose "Workflow Task" as the script type.

• After that, you can connect these scripts to a Workflow Transition Task.

Here is an example of how to use it:

You want to automatically change a status field, send an internal notification, or figure out a value based on business logic and set it whenever a document is approved.

Webhooks

When a transition happens, webhooks send real-time data to outside systems, such as APIs or third-party services.

• You need to set the webhook's "Doc Event" field to "workflow_transition" in order to use webhooks in workflows.

• You need to connect the webhook to a Workflow Transition Task after you've set it up. Use case example:

When the Sales Order changes from "To Deliver" to "Shipped," send the order details to an outside shipping company.

Discard
Save

On this page

Review Changes ← Back to Content
Message Status Space Raised By Last update on